package com.zfei.gfb.controller;

import cn.hutool.core.date.DateUtil;
import com.google.common.collect.Lists;
import com.zfei.gfb.bean.Const;
import com.zfei.gfb.bean.Status;
import com.zfei.gfb.bean.StatusException;
import com.zfei.gfb.core.Auth;
import com.zfei.gfb.core.HttpJson;
import com.zfei.gfb.core.LogResult;
import com.zfei.gfb.dao.GfbBannerMapper;
import com.zfei.gfb.device.AppContext;
import com.zfei.gfb.model.GfbBanner;
import com.zfei.gfb.model.GfbUser;
import com.zfei.gfb.request.GfbBannerAddRequest;
import com.zfei.gfb.request.GfbBannerEditRequest;
import com.zfei.gfb.request.GfbDelRequest;
import com.zfei.gfb.util.Beans;
import com.zfei.gfb.util.Now;
import com.zfei.gfb.vo.GfbBannerListVo;
import com.zfei.gfb.vo.GfbBannerVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * @version 1.0
 * @author
 * notes banner最多可发布五个，超过五个后无新增按钮
 */
@Api(tags = "H5 banner接口")
@RestController
@RequestMapping("/h5/banner")
public class H5BannerController {

	@Resource
	private GfbBannerMapper gfbBannerMapper;

	@ApiOperation(value = "列表")
	@ApiResponses({
			@ApiResponse(code = 200, message = "",response = GfbBannerListVo.class),
	})
	@LogResult
	@HttpJson("/list")
	public Object list() {

		GfbBannerListVo result = new GfbBannerListVo();

		int total = gfbBannerMapper.totalAll();
		result.setTotal(total);
		if (total == 0) {
			result.setData(Lists.newArrayList());
			return result;
		}

		List<GfbBanner> records = gfbBannerMapper.listAll();
		List<GfbBannerVo> vos  = Beans.copys(records,GfbBannerVo.class);
		result.setData(vos);

		return result;
	}

}
